﻿@using System.Xml.Linq
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
    <channel>
        <title>@T(Res.Name("Title"))</title>
        <link>http://@Request.Url.Host</link>
        <description>@(String.IsNullOrWhiteSpace(Model.Error) ? T(Res.Name("Description")) : Model.Error)</description>
        <lastBuildDate>@DateTime.UtcNow.ToString("r")</lastBuildDate>
        <language>@JDM.String(Svc.Localization.Code)</language>
	    <generator>@T(Res.Name("Generator"))</generator>
        <copyright>@T(Res.Name("Copyright"), DateTime.UtcNow.Year)</copyright>
        @if(Model.Data != null)
        {
            foreach(var i in (Model.Data as XElement).Elements("entry"))
            {
                string type = i.Attribute("Type").Value;
                var date = DateTime.FromBinary(i.Attribute("Date").Value.ParseAs<Int64>());
                int entityID = i.Attribute("EntityID").Value.ParseAs<Int32>();
                string title = i.Attribute("Title").Value;
                string link = "http://" + Request.Url.Host;
                string description = i.Attribute("Description").Value;
                if(type == "ForumTopic")
                {
                    description = BBCodeHelper.StripTags(description);
                    link += Url.Action(Loc.Act("Show").Ctrl("Topic").Area("Forum").Set(new
                    {
                        id = entityID
                    }).Localized());
                }
                else if(type == "ForumPost")
                {
                    description = BBCodeHelper.StripTags(description);
                    title = T(Res.In("Common").Of("Expr").Name("Re"), title);
                    link += Url.Action(Loc.Act("Show").Ctrl("Topic").Area("Forum").Set(new
                    {
                        id = entityID
                    }).Localized());
                }
                else if(type == "Publication_BlogPost")
                {
                    link += Url.Action(Loc.Act("Show").Ctrl("Post").Area("Blog").Set(new
                    {
                        id = entityID
                    }).Localized());
                }
                else if(type == "Publication_Article")
                {
                    link += Url.Action(Loc.Act("Show").Ctrl("Article").NoArea().Set(new
                    {
                        id = entityID
                    }).Localized());
                }
                else if(type == "Publication_News")
                {
                    link += Url.Action(Loc.Act("Show").Ctrl("News").NoArea().Set(new
                    {
                        id = entityID
                    }).Localized());
                }
                description = HtmlUtility.Encode(description);
                <item>
                    <category>@T(Res.Of("Type").Name(type))</category>
                    <title>@title</title>
                    @Html.Raw("<link>")@link@Html.Raw("</link>")
                    <pubDate>@date.ToString("r")</pubDate>
                    <description>@description</description>
                </item>
            }
        }
    </channel>
</rss>
